<template>
	<div>
		<div id="components-form-demo-advanced-search">
			<div class="h2">{{ ClubName }}学生组织公告</div>
		</div>
		<div>
			<a-form class="ant-advanced-search-form home-form" :form="form" @submit="handleSearch">
				<a-row :gutter="24">
					<a-col :span="8">
						<a-form-item label="公告标题">
							<a-input class="field-right" placeholder="请输入公告标题搜索" v-decorator="[`key`]" />
						</a-form-item>
					</a-col>
					<a-col :span="8" style="margin-top:4px;">
						<a-button type="primary" html-type="submit" class="btn1">搜索</a-button>
						<a-button :style="{ marginLeft: '8px' }" @click="handleReset" class="btn2">重置</a-button>
					</a-col>
				</a-row>
			</a-form>
		</div>
		<div class="option">
			<!-- <a-button  type="primary" class="btn" @click="addList">发起公告</a-button> -->
		</div>
		<div>
			<el-table ref="singleTable" :data="data" border highlight-current-row style="width: 100%">
				<el-table-column type="index" label="序号" width="60" fixed="left"></el-table-column>
				<el-table-column prop="Title" label="公告标题" min-width="100" ></el-table-column>
				<el-table-column prop="Content" label="公告内容" min-width="180" ></el-table-column>
				<el-table-column prop="AddUserName" label="发布人" min-width="80" ></el-table-column>
				<el-table-column prop="AddTime" label="发布时间" min-width="80" ></el-table-column>
				<el-table-column prop="IsEnable" label="操作" min-width="60" fixed="right">
					<template slot-scope="scope">
						<a-tooltip placement="top">
							<template slot="title">讨论</template>
							<i  title="讨论" class="iconfont icon-liaotian" @click="talk(scope.row)"></i>
						</a-tooltip>
						<a-tooltip placement="top">
							<template slot="title">修改</template>
							<i title="修改" class="iconfont icon-editor1" style="color: #1890ff;" @click="update(scope.row)"></i>
						</a-tooltip>
						<a-tooltip placement="top">
							<template slot="title">删除</template>
							<i title="删除" class="iconfont icon-delete1" style="color: red;" @click="deletemember(scope.row)"></i>
						</a-tooltip>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pagination.currentPage"
			 :page-sizes="pagination.pageSizeOptions" :page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper"
			 :total="pagination.total"></el-pagination>
		</div>
		<a-modal title="新增公告" :visible="visible" :confirm-loading="confirmLoading" @ok="handleOk" @cancel="applyhandleCancel">
			<a-form-model ref="ruleForm" :model="form1" :rules="rules1" :label-col="labelCol" :wrapper-col="wrapperCol">
				<!-- <a-form-model-item label="申请人" prop="Reason">
						<a-input disabled v-model="text.Name" type="text" />
					</a-form-model-item> -->
				<a-form-model-item label="公告标题" prop="Title">
					<a-input v-model="form1.Title" type="text" />
				</a-form-model-item>
				<a-form-model-item label="公告内容" prop="Content">
					<a-input v-model="form1.Content" type="textarea" :auto-size="global.textareaHeight" />
				</a-form-model-item>
				<!-- <a-form-model-item :wrapper-col="{ span: 14, offset: 4 }">
						<a-button type="primary" @click="onSubmit">
							提交
						</a-button>
					</a-form-model-item> -->
			</a-form-model>
		</a-modal>
		<a-modal title="修改公告" :visible="visible1" :confirm-loading="confirmLoading1" @ok="handleOk1" @cancel="applyhandleCancel">
			<a-form-model ref="ruleForm" :model="form2" :rules="rules1" :label-col="labelCol" :wrapper-col="wrapperCol">
				<!-- <a-form-model-item label="申请人" prop="Reason">
						<a-input disabled v-model="text.Name" type="text" />
					</a-form-model-item> -->
				<a-form-model-item label="公告标题" prop="Title">
					<a-input v-model="form2.Title" type="text" />
				</a-form-model-item>
				<a-form-model-item label="公告内容" prop="Content">
					<a-input v-model="form2.Content" type="textarea" :auto-size="global.textareaHeight" />
				</a-form-model-item>
				<!-- <a-form-model-item :wrapper-col="{ span: 14, offset: 4 }">
						<a-button type="primary" @click="onSubmit">
							提交
						</a-button>
					</a-form-model-item> -->
			</a-form-model>
		</a-modal>
	</div>
</template>

<script>
	import Func from '@/utils/func';
	import Cache from '@/utils/cache'
	import {
		GetMClubNewsList,
		DoAddClubNews,
		DoDeleteMClubNews,
		DoUpdateMClubNews,
		UserGetClubDetail
	} from '@/api/follow';
	const data = [];
	export default {
		components: {
			
		},
		data() {
			return {
				data,
				form: this.$form.createForm(this, {
					name: 'advanced_search'
				}),
				pagination: {
					currentPage: 1,
					pageSize: this.global.pageSize,
					pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
					showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
				},
				addIf: false,
				text: {},
				detailtext:{},
				codeID:'',
				visible: false,
				confirmLoading: false,
				itemId: '',
				departmentList: [],
				worklist: [],
				loading: false,
				values: {},
				pages: {
					pageIndex: 1,
					pageSize: 20
				},
				tableHeight: parseFloat(window.innerHeight - 160),
				TypeIDList: [],
				DepartCodeList: [],
				ProjectIDList: [],
				ishaveid: true,
				selectList: {},
				showModal: false,
				UserInfo: Cache.get('myInfo'),
				ChairmanNo: '',
				ClubName: this.$route.query.Name,
				thisChairmanNo:Cache.get('myInfo').UserNo,
				linktype: 1,
				ID: this.$route.query.ID,
				visible: false,
				deletelist: {},
				time:'',
				codeIf:false,
				detailIf:false,
				IsManager:false,
				visible: false,
				confirmLoading: false,
				form1: {
					Title: '',
					Content: ''
				},
				visible1: false,
				confirmLoading1: false,
				form2: {
					Title: '',
					Content: ''
				},
				labelCol: {
					span: 8
				},
				wrapperCol: {
					span: 14
				},
				rules1: {
					Title: [{
						required: true,
						message: '请输入公告标题',
						trigger: 'blur'
					}],
					Content: [{
						required: true,
						message: '请输入公告内容',
						trigger: 'blur'
					}],
				},
			};
		},
		computed: {},
		created() {
			// this.getList();
			this.GetOtherList()
		},
		mounted() {},
		methods: {
			update(text){
				this.visible1=true
				this.form2.Title=text.Title
				this.form2.Content=text.Content
				this.form2.ID=text.ID
			},
			talk(text){
				this.$router.push({
					name: 'ANoticeReply',
					query: {
						ID: text.ID,
						ChairmanNo: this.ChairmanNo,
						Title: text.Title,
						ClubID:this.ID
					}
				})
			},
			handleOk(e) {
				let data = {}
					this.$refs.ruleForm.validate(async valid => {
					if (valid) {
						data.ClubID = this.ID
						data.Title = this.form1.Title
						data.Content = this.form1.Content
						let res = await DoAddClubNews(data)
						if (res.data.code === 0) {
							this.$message.success(res.data.msg)
							this.$emit('closeFun')
							this.$refs.ruleForm.resetFields();
							this.GetOtherList()
							this.visible = false
						} else {
							this.$message.error(res.data.msg)
							this.$refs.ruleForm.resetFields();
						}
					}
				})
			
			},
			handleOk1(e) {
				let data = {}
					this.$refs.ruleForm.validate(async valid => {
					if (valid) {
						data.ID = this.form2.ID
						data.Title = this.form2.Title
						data.Content = this.form2.Content
						let res = await DoUpdateMClubNews(data)
						if (res.data.code === 0) {
							this.$message.success(res.data.msg)
							this.$emit('closeFun')
							this.visible1 = false
							this.$refs.ruleForm.resetFields();
							this.GetOtherList()
						} else {
							this.$message.error(res.data.msg)
						}
					}
				})
			
			},
			applyhandleCancel(e) {
				this.visible = false;
				this.visible1 = false
				this.$refs.ruleForm.resetFields();
			},
			async GetOtherList(){
			    let data={}
				if (this.values) {
					data = this.values;
				}
				data.clubID=this.ID
				// debugger
				let res = await GetMClubNewsList(data);
				this.data=res.data.data
				const pagination = { ...this.pagination
				};
				pagination.total = res.data.pageInfo.TotalItemCount;
				this.pagination = pagination;
				let data1={}
				data1.id=this.ID
				// let res1=await UserGetClubDetail(data1)
				// this.IsManager=res1.data.isManager
				// this.ChairmanNo=res1.data.data.ChairmanNo
			},
			 codeimg(text){
				// let data={}
				// data.id=text.ID
				// let res= await GetUserActivitySignQRImage(data)
				this.time=new Date()
				this.codeID=text.ID
				this.codeIf=true
			},
			handleCancel(e) {
				this.visible = false
				this.GetOtherList()
			},
			deletemember(text) {
				// this.visible = true
				// this.deletelist = text
				let that=this
				this.$confirm({
					title: '提示',
					content: `您确定删除此条记录吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {}
						data.id = text.ID
						let res = await DoDeleteMClubNews(data);
						if(res.data.code==0){
							that.GetOtherList()
							that.$message.success(res.data.msg)
						}else{
							that.$message.error(res.data.msg)
						}
					}
				})
			},
			detail(text) {
				this.text = text
				this.time=new Date()
				this.addIf = true
			},
			handleChange(val) {
				this.currentRow = val;
				if (val.ID) {
					this.ishaveid = false
					this.selectList = val
				} else {
					this.ishaveid = true
				}
			},
			handleSearch(e) {
				e.preventDefault();
				this.form.validateFields((error, values) => {
					this.pagination.currentPage = 1;
					this.values = values;
					this.GetOtherList()
				});
			},
			handleReset() {
				this.form.resetFields();
				this.values = {};
				this.GetOtherList()
			},
			handleSizeChange(val) {
				this.pagination.pageSize = val;
				this.GetOtherList()
			},
			handleCurrentChange(val) {
				this.pagination.currentPage = val;
				this.GetOtherList()
			},
			async getList() {
				this.loading = true;
				let data = {};
				if (this.values) {
					data = this.values;
				}
				data.activityID = this.$route.query.ID
				data.pageIndex = this.pagination.currentPage;
				data.pageSize = this.pagination.pageSize;
				let res = await UserActivityFile(data);
				this.loading = false;
				this.data = res.data.data;
				// const pagination = { ...this.pagination
				// };
				// pagination.total = res.data.pageInfo.TotalItemCount;
				// this.pagination = pagination;
			},
			// async getOtherList() {
			// 	let res = await UserUpdateActivity()
			// 	this.TypeIDList = res.data.data
			// },
			addList() {
				this.visible=true
			},
			modifyList(text) {
				text = Object.assign(text, {
					time: new Date()
				});
				this.addIf = !this.addIf;
				this.text = text;
			},
			closeFun(index) {
				this.visible2=false
				this.showModal = false
				this.addIf=false
				this.detailIf=false
				this.codeIf=false
				this.getList()
			},
		}
	};
</script>

<style lang="less" scoped>
	/deep/.ant-form-item {
		display: flex;
		margin-bottom: 10px !important;

		/deep/.ant-form-item-label {
			width: 100px;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
			text-align: right;
		}

		/deep/.ant-form-item-control-wrapper {
			flex: 1;
		}
	}


	/deep/.el-table th.is-leaf {
		background: #fafafa;
	}

	/deep/.el-table td,
	/deep/.el-table th {
		padding: 5px;
	}

	.option {
		margin-top: 10px;
		margin-bottom: 20px;
		overflow: hidden;
	}

	.option .btn {
		height: 36px;
		line-height: 36px;
		padding: 0 10px;
		float: left;
		background: #1890ff;
		color: #fff;
		margin-right: 10px;
		border-radius: 3px;
		cursor: pointer;
		border: none;
	}

	.foot {
		text-align: center;
		margin-top: 100px;
	}

	.el-pagination {
		margin-top: 10px;
	}

	.all {
		background-color: white;
		padding: 20px;
	}

	.joinok {
		width: 100%;
		text-align: center;
		margin-top: 20px;
	}

	i:hover {
		cursor: pointer;
	}
</style>
